<script setup>
  import { onBeforeRouteLeave, useRoute } from 'vue-router';
  import { watch, reactive } from 'vue';
  import { GetClosePositionPeriodType } from '@/api/exdoctor/exclose'
  const appRoute = useRoute()

  const pageData = reactive({
    data: {},
    tdata: [],
  })

  const getOverview = () => {
    const params = {
      fn: appRoute.query.fn,
      start: appRoute.query.start,
      end: appRoute.query.end
    }
    GetClosePositionPeriodType(params.fn, params.start, params.end).then((res) => {
      // console.log(res)
      pageData.data = res.data
      pageData.tdata = res.data.data
    })
  }

  const watchRouteTs = watch(() => appRoute.query._ts, () => {
    getOverview()
  }, { immediate: true})

  onBeforeRouteLeave(() => {
    watchRouteTs()
  })
</script>
<template>
  <div class="view-container">
    <div class="title-box">
      <div class="title">交易统计分析</div>
      <div class="sub-title">- 交易周期类型 -</div>
    </div>
    <div class="img-text">
      <el-image class="img-show" :src="pageData.data.img_url" fit="fill">
        <template #error>
          <div class="error-slot">
            数据加载中...
          </div>
        </template>
      </el-image>
    </div>
    <div class="table-box" v-loading="pageData.dataLoading">
      <el-row class="row">
        <el-col class="header col" :span="4">交易类型</el-col>
        <el-col class="header col" :span="5">成交额</el-col>
        <el-col class="header col" :span="5">总次数</el-col>
        <el-col class="header col" :span="5">盈利次数</el-col>
        <el-col class="header col" :span="5">胜率</el-col>
      </el-row>
      <el-row v-for="row in pageData.tdata" :key="row.t" class="row">
        <el-col class="header col" :span="4">{{ row.name }}</el-col>
        <el-col class="col" :span="5">{{ row.v }}</el-col>
        <el-col class="col" :span="5">{{ row.tc }}</el-col>
        <el-col class="col" :span="5">{{ row.gc }}</el-col>
        <el-col class="col" :span="5">{{ (row.r * 100).toFixed(2) }}%</el-col>
      </el-row>
    </div>
    <div class="img-text">
      <div class="txt-show">
        {{ pageData.data.txt }}
      </div>
    </div>
    <div class="tip-box">
      <div>提示说明：</div>
      <div>
        1. 统计结果按平仓记录核算。
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
  .view-container {
    padding: 0 20px 10px 20px;
    .title-box {
      // text-align: left;
      margin: 10px 0;
      line-height: 30px;
      .title {
        font-size: 22px;
        font-weight: 600;
        .sub-title {
          color: #444;
          font-size: 15px;
          
        }
      }
    }
    .img-text {
      .img-show {
        width: 660px;
        height: 330px;
        .error-slot {
          display: flex;
          justify-content: center;
          align-items: center;
          height: 100%;
          color: var(--el-text-color-secondary);
        }
      }
      .txt-show {
        line-height: 30px;
        margin-top: 10px;
        text-indent: 2em;
        background-color: #e7edfa;
        padding: 2px 10px;
        border-radius: 4px;
      }
    }
    .table-box {
      margin: 20px 0;
      .row {
        text-align: center;
        line-height: 30px;
        border-bottom: 1px solid #ebeef5;
        &:first-child {
          border-top: 1px solid #ebeef5;
        }
        .header {
          background-color: #f5f7fa;
          font-weight: 600;
          color: #606266;
          font-size: 15px;
        }
        .col {
          border-left: 1px solid #ebeef5;
          &:last-child {
            border-right: 1px solid #ebeef5;
          }
        }
      }
    }
    .tip-box {
      margin-top: 10px;
      line-height: 25px;
      font-size: 13px;
      color: #444;

    }
  }
</style>
